package com.itheima.controller.backend.security;

import com.itheima.DTOAndVO.OrderVO;
import com.itheima.DTOAndVO.SubmitOrderDTO;
import com.itheima.common.constant.MessageConstant;
import com.itheima.common.entity.Result;
import com.itheima.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Slf4j
@RequestMapping("/order")
public class OrderController {
    @Autowired
    private OrderService orderService;

    /**
     * 体检预约
     * @param submitOrderDTO
     * @return
     */
    @PostMapping("/submitOrder")
    public Result submitOrder(@RequestBody SubmitOrderDTO submitOrderDTO) throws Exception {
        log.info("体检预约:{}",submitOrderDTO);
        Integer id= orderService.submitOrder(submitOrderDTO);
        return new Result(true, MessageConstant.ORDER_SUCCESS,id);
    }

    /**
     * 根据预约id查询预约信息
     * @param id
     * @return
     */
    @GetMapping("/findById")
    public Result findById(String id){
        log.info("根据预约id查询预约信息:{}",id);
        OrderVO orderVO= orderService.findById(id);
        return new Result(true, MessageConstant.QUERY_ORDER_SUCCESS,orderVO);
    }

}
